package com.xjcs.saplingplan.dialog

import android.content.Context
import android.graphics.Color
import com.bigkoo.pickerview.adapter.NumericWheelAdapter
import com.lxj.xpopup.core.CenterPopupView
import com.xjcs.saplingplan.R
import com.xjcs.saplingplan.databinding.PopAdvanceRemindDaysBinding

class AdvanceRemindDaysPop(
    context: Context,
    private val callback: (Int) -> Unit
): CenterPopupView(context) {

    private lateinit var binding: PopAdvanceRemindDaysBinding

    override fun getImplLayoutId(): Int {
        return R.layout.pop_advance_remind_days
    }

    override fun onCreate() {
        super.onCreate()
        binding = PopAdvanceRemindDaysBinding.bind(contentView)
        initWheelView()

        //取消
        binding.tvCancel.setOnClickListener {
            dismiss()
        }
        //保存
        binding.tvSure.setOnClickListener {
            val select = binding.wheelView.adapter.getItem(binding.wheelView.currentItem)
            callback.invoke(select as Int)
            dismiss()
        }
    }

    private fun initWheelView() {
        binding.wheelView.adapter = NumericWheelAdapter(1, 60)
        binding.wheelView.setItemsVisibleCount(5)
        binding.wheelView.setCyclic(true)
        binding.wheelView.setDividerColor(Color.TRANSPARENT)
        binding.wheelView.setLineSpacingMultiplier(2f)
        binding.wheelView.currentItem = 0
    }

}